{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                {volist name="nameArray" id="vo"}
                <li class="{if $key==$name}layui-this{/if}"><a href="{:url('admin/sms/index',['name'=>$key])}">{$vo}</a>
                </li>
                {/volist}
            </ul>
            <div class="layui-tab-content">
                <form class="layui-form" method="post">
                    {if condition="$name == 'alisms'"}
                    <div class="layui-form-item">
                        <label class="">应用key和密钥你可以通过 <a href="https://dysms.console.aliyun.com/overview"
                                                                   target="_blank"> 阿里云</a>
                            获取</label>
                    </div>
                    {elseif condition="$name == 'hwsms'" /}
                    <div class="layui-form-item">
                        <label class="">APP接入地址、应用key和secret可以通过<a
                                href="https://www.huaweicloud.com/product/msgsms.html" target="_blank"> 华为云</a>
                            获取</label>
                    </div>
                    <div class="layui-form-item">
                        <label class="">APP接入地址</label>
                        <div class="layui-form-field-label">
                            <input type="text" name="app_url"
                                   placeholder="登录管理控制台，从国内短信“应用管理”或国际/港澳台短信“应用管理”页面获取"
                                   autocomplete="off" class="layui-input" value="{$info.app_url}"/>
                        </div>
                    </div>
                    {else /}
                    <div class="layui-form-item">
                        <label class="">应用key和密钥你可以通过 <a href="https://console.cloud.tencent.com"
                                                                   target="_blank"> 腾讯云</a>
                            获取</label>
                    </div>
                    <div class="layui-form-item">
                        <label class="">应用AppID</label>
                        <div class="layui-form-field-label">
                            <input type="text" name="appid" placeholder="请输入应用AppID" autocomplete="off"
                                   class="layui-input" value="{$info.appid}"/>
                        </div>
                    </div>
                    {/if}
                    <div class="layui-form-item">
                        <label class="">应用key</label>
                        <div class="layui-form-field-label">
                            <input type="text" name="key" placeholder="请输入应用key" autocomplete="off"
                                   class="layui-input" value="{$info.key}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="">秘钥secret</label>
                        <div class="layui-form-field-label">
                            <input type="text" name="secret" placeholder="请输入秘钥secret" autocomplete="off"
                                   class="layui-input" value="{$info.secret}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="">签名</label>
                        <div class="layui-form-field-label">
                            <input type="text" name="sign" placeholder="请输入签名" autocomplete="off"
                                   class="layui-input" value="{$info.sign}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="">短信模板
                            <button type="button" class="layui-btn layui-btn template">添加模板</button>
                        </label>
                        {if $info.template && count($info.template) > 0}
                        {volist name="$info.template" id="vo" key="key"}
                        <div class="template-item layui-form-item">
                            <label class="layui-form-label">标识：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="template[{$key-1}][key]" placeholder="请输入标识"
                                       autocomplete="off"
                                       class="layui-input" value="{$vo.key}">
                            </div>
                            <label class="layui-form-label">值：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="template[{$key-1}][value]" placeholder="请输入模板值"
                                       autocomplete="off" class="layui-input" value="{$vo.value}">
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <a href="#" class="del"><i class="layui-icon" style="font-size: 30px; color: red;">&#x1007;</i></a>
                            </div>

                        </div>
                        {/volist}
                        {else /}
                        <div class="template-item layui-form-item">
                            <label class="layui-form-label">标识：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="template[0][key]" placeholder="请输入标识" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <label class="layui-form-label">值：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="template[0][value]" placeholder="请输入模板值"
                                       autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                <a href="#" class="del"><i class="layui-icon" style="font-size: 30px; color: red;">&#x1007;</i></a>
                            </div>
                        </div>
                        {/if}

                    </div>

                    <div class="layui-form-item">
                        <div>
                            <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        $('.template').on('click', function () {
            // 获取当前已有的 template-item 数量
            var index = $('.template-item').length;

            // 创建新的 template-item 元素
            var newItem = `<div class="template-item layui-form-item">
                <label class="layui-form-label">标识：</label>
                <div class="layui-input-inline">
                    <input type="text" name="template[${index}][key]" placeholder="请输入标识" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">值：</label>
                <div class="layui-input-inline">
                    <input type="text" name="template[${index}][value]" placeholder="请输入模板值" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="#" class="del"><i class="layui-icon" style="font-size: 30px; color: red;">&#x1007;</i></a>
                </div>
            </div>`;

            // 将新的 template-item 插入到现有的最后一个 template-item 之后
            $('.template-item:last').after(newItem);
        });

        // 使用事件委托来绑定 .del 的点击事件
        $('.layui-form').on('click', '.del', function (e) {
            e.preventDefault(); // 阻止默认行为
            $(this).closest('.template-item').remove(); // 删除当前 .template-item
        });
    });
</script>
{/block}
